package com.kx.smartdevice.task;

import com.kx.smartdevice.event.CheckStatusEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 在这里开启定时任务，每隔10秒检查一次设备的状态
 *
 * @ClassName DeviceStatusTask
 * @Author Sun
 * @Date 2021/6/2 18:24
 */
@Component
public class DeviceStatusTask {

    @Autowired
    private ApplicationContext context;

    //开启定时任务，每隔10秒检查一次设备的状态
    @Scheduled(fixedRate=10000)
    public void CheckStatus() {
        System.err.println("检查状态的任务执行了");
        context.publishEvent(new CheckStatusEvent());
    }
}
